/**
 * 
 */
package com.agilegroup.crm.ui;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;

import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.ActionBar.Tab;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.agilegroup.crm.R;
import com.agilegroup.crm.adapters.MyFragmentPagerAdapter;

/**
 * @author Hisham
 *
 */
public class ViewLeadActivity  extends SherlockFragmentActivity {
	
	private ActionBar mActionBar;
	private ViewPager mPager;
	
	@Override
	protected void onCreate(Bundle arg0) {
		super.onCreate(arg0);
		
		setContentView(R.layout.view_pager);
		
		getSupportActionBar().setDisplayHomeAsUpEnabled(true);
		
		mActionBar = getSupportActionBar();
		mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
		mPager = (ViewPager) findViewById(R.id.pager);
		FragmentManager fm = getSupportFragmentManager();
		
		 ViewPager.SimpleOnPageChangeListener pageChangeListener = new ViewPager.SimpleOnPageChangeListener(){
	            @Override
	            public void onPageSelected(int position) {
	                super.onPageSelected(position);
	                mActionBar.setSelectedNavigationItem(position);
	            }
	        };
	        
	    mPager.setOnPageChangeListener(pageChangeListener);
	    MyFragmentPagerAdapter fragmentPagerAdapter = new MyFragmentPagerAdapter(fm);
	    
        /** Setting the FragmentPagerAdapter object to the viewPager object */
        mPager.setAdapter(fragmentPagerAdapter);
 
        mActionBar.setDisplayShowTitleEnabled(true);
        
        /** Defining tab listener */
        ActionBar.TabListener tabListener = new ActionBar.TabListener() {
 
            @Override
            public void onTabUnselected(Tab tab, FragmentTransaction ft) {
            }
 
            @Override
            public void onTabSelected(Tab tab, FragmentTransaction ft) {
                mPager.setCurrentItem(tab.getPosition());
            }
 
            @Override
            public void onTabReselected(Tab tab, FragmentTransaction ft) {
            }
        };
        Tab tab = mActionBar.newTab()
                .setText(getResources().getString(R.string.tab_lead_detials))
                .setTabListener(tabListener);
 
        mActionBar.addTab(tab);
 
        tab = mActionBar.newTab()
                .setText(getResources().getString(R.string.tab_lead_appointments))
                .setTabListener(tabListener);
 
        mActionBar.addTab(tab);
        
        tab = mActionBar.newTab()
                .setText(getResources().getString(R.string.tab_lead_calls))
                .setTabListener(tabListener);
 
        mActionBar.addTab(tab);
	}
	
//	@Override
//    public boolean onMenuItemSelected(int featureId, MenuItem item) {
//    	int itemId = item.getItemId();
//        switch (itemId) {
//        case android.R.id.home:
//             finish();
//            break;
//
//        }
//
//        return super.onOptionsItemSelected(item);
//    }
}